package realestate.manager.owner;

import javax.persistence.*;
import java.io.Serializable;

/**
 * Created by IntelliJ IDEA.
 * User: Admin
 * Date: 08.04.11
 * Time: 14:35
 * To change this template use File | Settings | File Templates.
 */
@Table(name = Owner.TABLE_NAME)
@Entity
@NamedQueries(
	{
		@NamedQuery(name = Owner.OWNER_BY_E_MAIL, query = "select o from Owner o where o.e_mail=?1"),
		@NamedQuery(name = Owner.OWNER_BY_KEY, query = "select o from Owner o where o.hashKey=?1")
	}
)
public class Owner implements Serializable {

	public static final String TABLE_NAME = "owner";

	public static final String FIELD_ID = "id";
	public static final String FIELD_E_MAIL = "e_mail";
	public static final String FIELD_KEY = "hashKey";

	public static final String OWNER_BY_E_MAIL = "owner.find_by_e_mail";
	public static final String OWNER_BY_KEY = "owner.find_by_key";

	@Id
	@GeneratedValue
	private Long id;

	@Column(name = FIELD_E_MAIL, unique = true)
	private String e_mail;

	@Column(name = FIELD_KEY, unique = true)
	private String hashKey;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getOwnerEMail() {
		return e_mail;
	}

	public void setOwnerOwnerEMail(String owner_e_mail_address) {
		this.e_mail = owner_e_mail_address;
	}

	public String getKey() {
		return hashKey;
	}

	public void setKey(String key) {
		this.hashKey = key;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (!(o instanceof Owner)) return false;

		Owner owner = (Owner) o;

		if (e_mail != null ? !e_mail.equals(owner.e_mail) : owner.e_mail != null) return false;
		if (id != null ? !id.equals(owner.id) : owner.id != null) return false;
		if (hashKey != null ? !hashKey.equals(owner.hashKey) : owner.hashKey != null) return false;

		return true;
	}

	@Override
	public int hashCode() {
		int result = id != null ? id.hashCode() : 0;
		result = 31 * result + (e_mail != null ? e_mail.hashCode() : 0);
		result = 31 * result + (hashKey != null ? hashKey.hashCode() : 0);
		return result;
	}
}